<form class="form-inline" id="tag_list_form">
	<div class="form-group">
		<div class="input-group">
            <div class="input-group-addon"> 标签名称</div>
            <input type="text" class="form-control" name="name"/>
        </div>
	</div>
	<div class="input-group">
		<div class="input-group-addon"> 标签类型</div>
		<select id="bizType" name="bizType" class="form-control">
			<option value="0" selected="selected">全部</option>
			<option value="1">样例</option>
			<option value="2">样例单页</option>
			<option value="3">样例组件</option>
		</select>
	</div>

	<br/>
	<button type="button" class="btn btn-primary" onclick="query_tag_list('#tag_list_grid', '/m/ie/tag/list.json')" >查询</button>
    <button type="button" class="btn btn-primary" onclick="openCreatetagWin()">新增标签</button>
    <button type="button" class="btn btn-primary" onclick="batchDeleteTag()">删除选中标签</button>
</form>
<table id="tag_list_grid" data-toggle="table" data-toolbar="#tag_list_form" data-unique-id="id" data-query-params="tag_query_params" data-click-to-select="true" data-page-size="5">
	<thead>
	    <tr>
	        <th data-valign="middle" data-checkbox="true">全选</th>
	    	<th data-field="id">ID</th>
	    	<th data-field="name">标签名称</th>
	    	<th data-field="description">标签描述</th>
	    	<th data-field="sort">排序</th>
	    	<th data-field="bizType" data-formatter="bizType_formatter">标签类型</th>
	    	<th data-field="createTime" data-formatter="log_formatter_time">创建时间</th>
	    	<!--th data-field="createUser">创建者</th-->
	    	<th data-valign="middle" data-field="id" data-align="center" data-formatter="business_operation_format" class="action-buttons" data-width="130">操作</th>				
	    </tr>
    </thead>
</table>
<div id="tag_model" class="modal fade" role="dialog" aria-labelledby="tag_model_title">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="tag_model_title">标签业务</h4>
            </div>
            <div class="modal-body">
                <form class="form-inline" id="tagForm">
                   <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon">标签ID</div>
                            <input type="text" id="id" value="" name="id" class="form-control" style="width: 450px;" >
                        </div>
                    </div>
                    <br/><br/>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon">标签名称</div>
                            <input type="text" id="name" value="" name="name" class="form-control" style="width: 450px;">
                        </div>
                    </div>
                    <br/><br/>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon">标签描述</div>
                            <input type="text" id="description" value="" name="description" class="form-control" style="width: 450px;">
                        </div>
                    </div>
                    <br/><br/>
                    <div class="form-group">
                        <div class="input-group">                            
                        	<div class="input-group-addon">标签类型</div>
                    		<select id="bizType" name="bizType" class="form-control">
								<option value="0" selected="selected">全部</option>
								<option value="1">样例</option>
								<option value="2">样例单页</option>
								<option value="3">样例组件</option>
							</select>
				 		</div>
					</div>	
					 <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon">标签排序</div>
                            <input type="text" id="sort" value="" name="sort" class="form-control" style="width: 450px;">
                        </div>
                    </div>
					
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="submittagForm()">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript">
//查询
    function query_tag_list(id, url) {
        $(id).bootstrapTable('refresh', {url: url});
    }  
     function tag_query_params(params) {
        $('#tag_list_form :input').each(function() {
            if($(this).attr('name')) {
                params[$(this).attr('name')] = $(this).val();
            }
        });
        return params;
    }
    function business_operation_format(value, item) {
        return '<button type="button" class="btn btn-link" onclick="openUpdatetagWin('+value+')">编辑</button>';
    }
    function submittagForm() {
    <!-- 使用ajax发送请求信息 -->
        $.ajax({
            url :  "/m/ie/tag/save",
            type : "POST",
            data: $('#tagForm').serialize(),
            success:function(data,ts,xhr){
                if(data.success){
                    $('#tag_model').modal('hide');
                    success(data.msg);
                }else{
                    error(data.msg);
                }
                $('#tag_list_grid').bootstrapTable('refresh');
            }
        });
    }
     function openCreatetagWin() {
        $('#id').attr('readonly', true);
        $('#tagForm')[0].reset();
        $('#tag_model').modal('show');
    }
    
    function openUpdatetagWin(id) {
        $('#id').attr('readonly', true);
        $('#tagForm')[0].reset();
        setFormValue('tagForm', $('#tag_list_grid').bootstrapTable('getRowByUniqueId', id));
        $('#tag_model').modal('show');
    }

    function log_formatter_time(value) {
       return new Date(value).format('yyyy-MM-dd hh:mm:ss');
    }
    function bizType_formatter(value) {
    	if(value == 1) return "样例";
    	if(value == 2) return "样例单页";
    	if(value == 3) return "单页组件";
    }
    
    function batchDeleteTag(id) {
		var data = {};
		if(id) {
			data.id = id;
		} else {
			data = $('#tag_list_grid').bootstrapTable('getSelections');
		}
		if(!data || data.length <= 0) {
			error('请选择标签！');
			return;
		}
		var ids = [];
		$(data).each(function(idx, item) {
			ids.push(item.id);
		});
		var ajaxData = {
			ids: ids.join(';')
		};
		openDialog({
			title: '删除',
			message: '您确认要删除这些标签吗？',
			okAction: function() {
				closeDialog();
				$.ajax({
					type: "post",
					url: "/m/ie/tag/delete",
					async: true,
					data: ajaxData,
					success: function(data) {
						if(data.success) {
							success(data.msg);
						} else {
							error("error");
						}
						$('#tag_list_grid').bootstrapTable('refresh');
					}
				});
			}
		})
	}
</script>